package view;

import control.Cont_relogio;
import static java.lang.Thread.sleep;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Testes extends javax.swing.JFrame {

	/**
	 * Creates new form Testes
	 */
	public Testes() {
		initComponents();
	}//CONSTRUTOR

	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lbl_data = new javax.swing.JLabel();
        lbl_hora = new javax.swing.JLabel();
        lbl_1 = new javax.swing.JLabel();
        lbl_2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        lbl_data.setText("jLabel1");

        lbl_hora.setText("jLabel1");

        lbl_1.setText("jLabel1");

        lbl_2.setText("jLabel2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl_hora, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                    .addComponent(lbl_data, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl_1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl_2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(189, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addComponent(lbl_data)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_hora)
                .addGap(65, 65, 65)
                .addComponent(lbl_1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_2)
                .addContainerGap(93, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
		 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(Testes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(Testes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(Testes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(Testes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
        //</editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new Testes().setVisible(true);
			}
		});
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbl_1;
    private javax.swing.JLabel lbl_2;
    private javax.swing.JLabel lbl_data;
    private javax.swing.JLabel lbl_hora;
    // End of variables declaration//GEN-END:variables

//	public void Inicia(){
//	
//		Cont_relogio relogio = new Cont_relogio();
//		
//		String a =relogio.InsereData();
//		this.lbl_data.setText(a);
//		
//		String b =relogio.InsereHora();
//		this.lbl_hora.setText(b);
//	
//	}//INICIA

	         //DATA E HORA
         public void InsereDataHora(){
    
		//NOVA THREAD
		new Thread() {
			
			@Override
			public void run() {

				for(;;) {

					//Instancia o calendario gregoriano
					GregorianCalendar Calendar = new GregorianCalendar();
					//Captura o dia
					int dia = Calendar.get(GregorianCalendar.DAY_OF_MONTH);
					Calendar data = Calendar.getInstance();

					//Captura o mês
					String mes="";
					switch(data.get(Calendar.MONTH)+1) {
						case 1:mes="Janeiro"; break;
						case 2:mes="Fevereiro‎"; break;
						case 3:mes="Março‎"; break;
						case 4:mes="Abril‎"; break;
						case 5:mes="Maio"; break;
						case 6:mes="Junho"; break;
						case 7:mes="Julho"; break;
						case 8:mes="Agosto"; break;
						case 9:mes="Setembro"; break;  
						case 10:mes="Outubro"; break; 
						case 11:mes="Novembro"; break; 
						case 12:mes="Dezembro"; break;
						default:mes="Mês Inválido"; break;
					}//SWITCH

					//Captura o ano
					int ano = Calendar.get(GregorianCalendar.YEAR);

					//Finaliza com a data atual
					lbl_data.setText(dia+"/"+mes+"/"+ano);
					
					//Define o relógio com a hora atual
					int hora=Calendar.get(GregorianCalendar.HOUR_OF_DAY);//HORA
					int min=Calendar.get(GregorianCalendar.MINUTE);//MINUTOS
					int seg=Calendar.get(GregorianCalendar.SECOND);//SEGUNDOS

					//Variaveis que serão exibidas 
					final String horaString;
					final String minString;
					final String segString;

					//Condição para aplicar um 0 caso a hora seja de apenas 1 digito
					if(hora<10) {
					horaString="0"+hora;
					} else {
					   horaString=""+hora;
					}//IF

					//Condição para aplicar um 0 caso os minutos sejam de apenas 1 digito
					if(min<10) {
						minString="0"+min;
					} else {
					   minString=""+min;
					}//IF

					//Condição para aplicar um 0 caso os segundos sejam de apenas 1 digito
					if(seg<10) {
						segString="0"+seg;
					} else {
					   segString=""+seg;
					}//IF

					//Finaliza com o relógio que será exibido
					lbl_hora.setText(horaString+":"+minString+":"+segString);

					//Define o tempo de atualização do label
					try {
						  sleep(1000);
						}//TRY
					catch (InterruptedException ex) {
					 System.out.println("Ocorreu um erro");
					}//CHATCH  

				}//FOR

			}//RUN

		}//THREAD
		.start();

	}//DATA HORA
	
}//CLASS
